clear
set more off
set type double
graph drop _all
program drop _all
set scheme s2mono
import excel "\\file\UsersW$\wrr15\Home\My Documents\My Files\ANDY KIM\REVISION FOR WORLD DEVELOPMENT\DATA AND CODE\MA Data (13 July 2016).xlsx", firstrow case(lower)
log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\ANDY KIM\REVISION FOR WORLD DEVELOPMENT\DATA AND CODE\Part2.smcl", replace

// RECODING VARIABLES
// The first thing we do is generate some new variables
// because some of our old study characteristics had too few
// observations
gen endog = (tsls == 1 | gmm == 1)
gen se_notols = (se_het == 1 | se_other == 1)
gen fdigdp = fditype0

// This section transforms the continuous variables so they are 
// deviations from the mean.  This makes the constant more "interpretable".
gen pubyear2 = pubyear
egen pubyearm = mean(pubyear2)
replace pubyear = pubyear2 - pubyearm

gen datayear2 = datayear
egen datayearm = mean(datayear2)
replace datayear = datayear2 - datayearm

gen span2 = span
egen spanm = mean(span2)
replace span = span2 - spanm

gen journalrank2 = journalrank
egen jrmean = mean(journalrank2)
replace journalrank = journalrank2 - jrmean


//CONVERTING TSTATS TO PARTICAL CORRELATION COEFFICIENTS, r
gen eff = sqrt(tstat^2/(tstat^2+df))
gen r = eff if positive == 1
replace r = -1*eff if r == .
gen varR = (1-r^2)/df
gen seR = sqrt(varR)
gen pcc = r



*--------------------------------------------------------------------------------*
*   TABLE 5: Fixed Effects Meta-Regression                                       *
*--------------------------------------------------------------------------------*

//METAREGRESSION - FIXED EFFECTS
gen pubyearr = pubyear/seR 
gen datayearr = datayear/seR 
gen spann = span/seR 
gen subsett = subset/seR 
gen fdigdpp = fdigdp/seR
gen initiall = initial/seR
gen endogg = endog/seR
gen se_notolss = se_notols/seR
gen dvtype11 = dvtype1/seR 
gen dvtype22 = dvtype2/seR 
gen dvtype_otherr = dvtype_other/seR 
gen panel_nofee = panel_nofe/seR 
gen panel_fee = panel_fe/ seR 
gen tss = ts/seR   
gen cjournall = cjournal/seR 
gen notjournall = notjournal/seR 
gen conss = 1/seR
gen fetstatR = r/seR 
gen journalrankk = journalrank/seR


// FIXED EFFECTS - Full Specification

// These specifications include the SeR term
// NOTE: The constant term is the SER term

//This first regression gives equal weight to each observation
// TABLE 5 - Col 1
reg fetstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss,  vce(cluster id)
display e(r2_a)

//This regression gives equal weight to each study
// TABLE 5 - Col 3
reg fetstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss [pweight = weight], vce(cluster id)
display e(r2_a)


// NOTE: These specification omit the SeR term

//This first regression gives equal weight to each observation
// TABLE 5 - Col 2
reg fetstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss, noc vce(cluster id)
display e(r2_a)

//This regression gives equal weight to each study
// TABLE 5 - Col 4
reg fetstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss [pweight = weight], noc vce(cluster id)
display e(r2_a)



/*

// FIXED EFFECTS - Stepwise Specification where SeR term can be kept or dropped

gen ser = 1

//This first regression gives equal weight to each observation
stepwise, pr(0.05) lockterm1:reg fetstatR conss pubyearr datayearr spann ///
subsett fdigdpp initiall endogg se_notolss dvtype11 dvtype22 dvtype_otherr ///
panel_nofee panel_fee tss cjournall notjournall ser, noc cluster(id)
display e(r2_a)

//This first regression gives equal weight to each observation
stepwise, pr(0.05) lockterm1:reg fetstatR conss pubyearr datayearr spann ///
subsett fdigdpp initiall endogg se_notolss dvtype11 dvtype22 dvtype_otherr ///
panel_nofee panel_fee tss cjournall notjournall ser [pweight = weight], noc cluster(id)
display e(r2_a)
*/
log close

